package de.velvettear.squirrel.gui;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import de.velvettear.squirrel.R;

public class MainFrame extends Activity implements OnClickListener {

	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.activity_mainframe);
	    
	    init();  
	}

	private void init() {
		Button btn_network = (Button) findViewById(R.id.mainframe_btn_network);
	    btn_network.setOnClickListener(this);
	    
	    Button btn_zip = (Button) findViewById(R.id.mainframe_btn_zip);
	    btn_zip.setOnClickListener(this);
	    
	    Button btn_security = (Button) findViewById(R.id.mainframe_btn_security);
	    btn_security.setOnClickListener(this);
	    
	    Button btn_chat = (Button) findViewById(R.id.mainframe_btn_chat);
	    btn_chat.setOnClickListener(this);
	    
	    Button btn_securitycam = (Button) findViewById(R.id.mainframe_btn_securitycam);
	    btn_securitycam.setOnClickListener(this);
	    
	    Button btn_shortcuts = (Button) findViewById(R.id.mainframe_btn_shortcuts);
	    btn_shortcuts.setOnClickListener(this);
	    
	    Button btn_settings = (Button) findViewById(R.id.mainframe_btn_settings);
	    btn_settings.setOnClickListener(this);	  
	    
	    Button btn_nfc = (Button) findViewById(R.id.mainframe_btn_nfc);
	    btn_nfc.setOnClickListener(this);
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		
		case R.id.mainframe_btn_network:
			startActivity(new Intent(MainFrame.this, NetworkFrame.class));
			break;
		
		case R.id.mainframe_btn_zip:
			startActivity(new Intent(MainFrame.this, ZipFrame.class));
			break;
			
		case R.id.mainframe_btn_security:
			startActivity(new Intent(MainFrame.this, PasswordsFrame.class));
			break;
			
		case R.id.mainframe_btn_chat:
			startActivity(new Intent(MainFrame.this, ChatFrame.class));
			break;
			
		case R.id.mainframe_btn_securitycam:
			startActivity(new Intent(MainFrame.this, SecurityCamFrame.class));
			break;
			
		case R.id.mainframe_btn_shortcuts:
			startActivity(new Intent(MainFrame.this, ShortCutFrame.class));
			break;
			
		case R.id.mainframe_btn_settings:
			startActivity(new Intent(MainFrame.this, SettingsFrame.class));
			break;			
			
		case R.id.mainframe_btn_nfc:
			startActivity(new Intent(MainFrame.this, NFCFrame.class));
			break;
			
		}		
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {		
		getMenuInflater().inflate(R.menu.menu_mainframe, menu);
		return super.onCreateOptionsMenu(menu);	
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {		
		switch(item.getItemId()) {
			
		case R.id.menu_mainframe_about:
			startActivity(new Intent(MainFrame.this, About.class));
			break;
		
		}
		
		return super.onOptionsItemSelected(item);
	}
	
	@Override
	public void onBackPressed() {
		AlertDialog exitDialog = new AlertDialog.Builder(this).create();
		exitDialog.setTitle("Exit");
		exitDialog.setMessage("Do you really wish to exit?");
		exitDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() {			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				finish();
			}
		});
		exitDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "No", new DialogInterface.OnClickListener() {			
			@Override
			public void onClick(DialogInterface dialog, int which) {
								
			}
		});
		exitDialog.show();
	}
	
}
